<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

echo "this is access token file ";

 /*   define('APP_ID','120005274854592');
    define('SECRET','a7f7790809678a06dba58eec8c3b5aca');
    define('URL','https://apps.facebook.com/samayville');
     $param = 'friends_about_me,friends_action.music,friends_actions.news,friends_actions.video,
                    friends_activities,friends_birthday,friends_education_history,
                    friends_events';
     
    $auth_url="https://www.facebook.com/dialog/oauth?client_id=".APP_ID.
            "&redirect_uri=".  urlencode(URL)."&scope='".$param."'";
    
     echo $auth_url;

     
     $signed_request = $_REQUEST['signed_request'];
     list($encoded_sig,$payload) = @explode(".", $signed_request, 2);
     echo $encoded_sig;
     //decoding the data which contains the access tokens now - niraj
     
     $data = json_decode(base64_decode($strtr($payload,'-_','+/')),true);
     if(empty($data['user_id'])){
         echo ("<script> top.location.href=".$auth_url."</script>");
     }*/

    require_once 'facebook-sdk/src/facebook.php';
    $config = array(
        'appId' => '120005274854592',
        'secret' => 'a7f7790809678a06dba58eec8c3b5aca'
    );

    $appId = '120005274854592';
    $canvas_page = "https://apps.facebook.com/samayville/";
    
    $facebook = new Facebook($config);
   // $getKey='/1810869839?fields=friends.fields(interested_in,religion,work,relationship_status,events,interests,hometown,sports,statuses.fields(likes,updated_time))';
    $getKey = '/1810869839?fields=name,friends,hometown,favorite_teams,interested_in,religion,relationship_status,timezone,games,sports,movies,music,television';
    
    try{
        
//        $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
//            . $appId . "&redirect_uri=" . urlencode($canvas_page) . ("&scope=friends_about_me,friends_activities ,friends_birthday ,friends_checkins ,friends_education_history ,friends_events ,friends_games_activity ,friends_groups ,friends_hometown ,friends_interests ,friends_likes ,friends_location ,friends_notes ,friends_online_presence ,friends_photo_video_tags ,friends_photos ,friends_questions ,friends_relationship_details ,friends_relationships ,friends_religion_politics ,friends_status ,friends_subscriptions ,friends_videos ,friends_website ,friends_work_history &response_type=token");
    $user_profile = $facebook->api($getKey,'GET');
    		foreach($user_profile['friends'] as $key)
		{
			foreach($key as $num)
                            if(!is_null($num['name']) && !is_null($num['id']))
				echo "<b>Name:".$num['name']."</b><i> Identification:".$num['id']."</i><br>"."<img src='https://graph.facebook.com/".$num['id']."/picture' width='50' height='50' title='".$num['name']."' />";
		}

    print_r($user_profile);
    //    echo $auth_url;
    }
    catch(OAuthException $oae){
        print_r($oae);
    }
    catch(CurlException $ce){
        print_r($ce);
    }
?> 

